package jmu.edu.yjc.controller;

import jmu.edu.yjc.domain.ResponseResult;
import jmu.edu.yjc.domain.entity.neo4j.dto.DiseabledDto;
import jmu.edu.yjc.service.neo4j.DiseabledService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Arrays;

@RestController
@RequestMapping("/knowledge/diseabled")
public class DiseabledController {
    @Resource
    private DiseabledService diseabledService;
    @GetMapping("/list")
    public ResponseResult getDiseabledList(Integer pageNum, Integer pageSize,
                                      String name) {
        return diseabledService.getDiseabledList(pageNum, pageSize, name);
    }

    @PostMapping
    public ResponseResult addDiseabled(@RequestBody DiseabledDto dto) throws IOException {

        return diseabledService.saveDiseabled(dto);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delDiseabled(@PathVariable("id") String id) {
        String[] ids = id.split(",");
        return diseabledService.removeByIds(Arrays.asList(ids));
    }

    @PutMapping
    public ResponseResult updateDiseabled(@RequestBody DiseabledDto disease) {
        return diseabledService.updateById(disease);
    }

    @GetMapping("/{id}")
    public ResponseResult getDiseabled(@PathVariable("id") Long id) {
        return  diseabledService.getById(id);
    }
    @GetMapping("/searchNodeByName")
    public ResponseResult searchNodeByName(String relation,String type,String query){
        return diseabledService.searchNodeByName(relation,type,query);
    }
    @GetMapping("/updateCache")
    public ResponseResult updateCache(){
        return diseabledService.updateCache();
    }

    @GetMapping("/total")
    public ResponseResult getTotal() {
        return diseabledService.getTotal();
    }
    @GetMapping("/randomDisable")
    public ResponseResult randomDisable(Integer total) {
        return diseabledService.randomDisable(total);
    }
}
